<!-- rss feed code starts here -->
	<?php 
	$siteName = cr('cmsConfig.Backend.siteName');?>
	<?php
	if($hideRssFeed == false)
	{?>
		<link rel="alternate" type="application/rss+xml" title="<?php echo sprintf(__("%s - Listing"),$siteName);?>" href="<?php echo $appHtml->url('/listings/index.'.'rss')?>" />
	<?php }?>
<!-- rss feed code ends here -->
<section class="hauptseite listings">
	<div class="container">
		<div class="row">
			<h2><?php echo __('Search Result');?></h2>
	<?php
	//unset is neccesary
	unset($paginator->Html);
	$paginator->Html = $appHtml; 
	//render element for review filter.
	//echo $this->element("index_map");
	if(!empty($listingData))
	{
		//echo $this->element('listing_filter');
	}
	?>
	<?php
	//show Go Back link for range and filter module only.
	if(isset($referer) && empty($this->params['isAjax']))
	{
		echo $html->link('<< '.__('Go Back'),$referer);
	}
	if(isset($category))
	{
		echo $html->link(__('Add new listing'), $category['ListCategory']['listingAddUrl'], array('class'=>'button'));
	}
	?>
	
	<?php 
  
    $pagingUrl = $this->getPagingUrl();
    //support for $_GET base search.
    $getParams = $_GET;
    unset($getParams['url']);
    $pagingUrl['?'] = $getParams;
	$paginator->options(array('url'=>$pagingUrl));
	if(!empty($listingData)){
	?>
		<?php echo $this->element('listings', array('listings' => $listingData,'view_type'=>$view_type));?>
<div class='paginate'>
	<?php echo $paginator->prev(__('Prev'));?>
	<?php echo $paginator->numbers(array('separator'=>' '));?>
	<?php echo $paginator->next(__('Next'));?>
</div>

<div class="clear"></div>
	<?php }
	else
	{
		echo "<h4 class='no_results'>".__('No listings found!')."</h4>";
	}
	?>
	<?php
	if(isset($compareListing) && $compareListing == true)
	{
		echo $this->element('compare_listing');
	}
	?>		
		</div>
	</div>
</section>
<div class="clear"></div>
<?php $javascript->link('/cms/js/jquery.ajaxify.js',false);
$javascript->link('/js/jquery.address.js',false);?>
<script type="text/javascript">
$(document).ready(function()
{
	<?php if(!isset($combinedResult) || $combinedResult == false){?>
	makeAjaxified($('#listing_block').find('#sortLink,.paginate a'),'listing_block');
	<?php }else{?>
		makeAjaxified($('#listing_block').find('#sortLink,.paginate a'),'listing_block',{noAddressChange:true});
	<?php } ?>	
});
</script>
<?php 
	//@MAPAJAXHK
	//@GEOMAP INTERSECTION.
	//this in being done in order make map funtional in case ajax request
	if($this->params['isAjax'] == true)
	{
		$mapJson = $geoMap->getListingsMarkerJson($listingData);	
?>
	<script>
		if($('#map_container_index').length != 0)
		{
			$('#map_index').html("");
			makeListingMap('map_index',<?php echo $mapJson?>,true);
		}
	</script>	
<?php 	}
?>
<?php 
	echo $html->css('/backend/css/scrollable.css',null,array(),false);
	echo $html->css('/css/compare_footer.css',null,array(),false);
	echo $javascript->link('/backend/js/jquery.tools.min.js',false);
	echo $javascript->link('/js/jquery.ez-pinned-footer.js',false);
?>
<script type="text/javascript">
var listingIdArr = new Array;
var compareFieldCount = 0;

if($.cookie('compareListing'))
{
	listingIdArr = $.cookie('compareListing');
}

if($.cookie('compareFieldCount'))
{
	compareFieldCount = $.cookie('compareFieldCount');
}

$(document).ready(function()
{
	var listingIdsToLoad = $.cookie('compareListing');
	var compareFieldCount = $.cookie('compareFieldCount');
	if(listingIdsToLoad &&   compareFieldCount > 0)
	{
		url = URL+'listings/loadListing/'+'listing_ids:'+listingIdsToLoad;
		$.get(url, function(data)
		{		
			$('.selectedListing div.items').html(data);
			pinFooter();
			if($('.selectedListing div.items').children().length > 5)
			{
				$(".scrollable").scrollable();
			}	
		});	
		showListingCount();
	}	
	checkCookieExistance();
	checkSelectedListing();	
});
function showListingCount()
{
	compareFieldCount = $.cookie('compareFieldCount');
	countHtml = '<h3><?php echo __("Compare Listings");?>('+compareFieldCount+')</h3>';
	$('.compare_count').html(countHtml);
}
	
function checkSelectedListing()
{
	listingId = $.cookie('compareListing');	
	compareFieldCount = $.cookie('compareFieldCount');
	$('.checkListing').attr('checked',false);	
	if(listingId && compareFieldCount > 0)
	{
		listingData = listingId.split(',');
		for (x in listingData)
		{
			id = listingData[x];
			$('#listing_'+id).attr('checked',true);
		}		
	}	
}	

function selectListing(obj,removableListing)
{	
	compareFieldCount = $.cookie('compareFieldCount');
	var listingIdArr = $.cookie('compareListing');
	if(listingIdArr == null)
	{
		var listingIdArr = "";
	}
	type = typeof(obj);
	if(type == 'object')
	{
		mainId = $(obj).attr('id');
	}else
	{
		mainId = obj;
	}
	splitedMainId = mainId.split('_');
	if($('#'+mainId).attr('checked') == 'checked')
	{
			relValue = $(obj).attr('rel');
			$('.selectedListing div.items').append(relValue); 
			
			id = splitedMainId[1];	
			compareFieldCount++;
			if(listingIdArr && typeof listingIdArr == 'object')
			{
					listingIdArr.push(id);
				
			}else
			{
				listingIdArr = listingIdArr.split(',');
				listingIdArr.push(id);	
			}		
			if(listingIdArr.length > 5)
			{
				$(".scrollable").scrollable();
			}
			id = null;			
	}else
	{
		id = splitedMainId[1];		
		compareFieldCount--;
		if(listingIdArr && typeof(listingIdArr) == 'object')
		{
			listingIdArr.splice(listingIdArr.indexOf(id), 1);	
		}else
		{
			listingIdArr = listingIdArr.split(',');
			listingIdArr.splice(listingIdArr.indexOf(id), 1);
		}	
		if(removableListing == true)
		{
			removeListing(mainId,false);
		}
		id = null;
	}	
	$.cookie('compareListing', listingIdArr, { expires: 1, path: '/'});
	$.cookie('compareFieldCount', compareFieldCount, { expires: 1, path: '/'});
	showListingCount();
	checkCookieExistance();
	pinFooter();

	
}

function triggerCompare()
{
	compareFieldCount = $.cookie('compareFieldCount');
	listingIdArr = $.cookie('compareListing');
	if(compareFieldCount < 2)
	{
		alert('<?php echo __("You need to select more than one listing for comparison!")?>');
	}else
	{
		var listingIds = listingIdArr;
		url = URL+'listings/compare/'+'listing_ids:'+listingIds;
		window.open(url,'Compare','top:0,left:0,width=820,height=600,resizable=yes,scrollbars=yes');
	}
	return false;		
}

function removeListing(obj,updateParam)
{	
	if(typeof(obj) == 'object')
	{
		mainId = $(obj).attr('rel');
	}else
	{
		mainId = obj;		
	}
	$('#'+mainId).attr('checked',false);
	if(updateParam == true)
	{
		selectListing(mainId,false);		
	}	
	$('.selectedListing div.items').find('div#'+mainId).remove(); 
	
	pinFooter();
}

function clearCookies()
{	
	$.cookie('compareListing', null, { expires: -1, path: '/'});
	$.cookie('compareFieldCount', null, { expires: -1, path: '/'});
	$('.compare_count').html('');
	$('.selectedListing div.items').html('');
	$('.comparision_list').hide();
	$('.checkListing').attr('checked',false);
	var listingIdArr = new Array;
	
	$.cookie('compareListing', listingIdArr, { expires: 1, path: '/'});
	$.cookie('compareFieldCount', 0, { expires: 1, path: '/'});

	return false;
}

function checkCookieExistance()
{
	var compareListing = $.cookie('compareListing');
	var compareFieldCount = $.cookie('compareFieldCount');
	if(compareFieldCount > 0)
	{
		$('.comparision_list').show();
	}else
	{
		clearCookies();
	}		
}

$(window).load(pinFooter);
$(window).bind("resize", pinFooter);

function pinFooter()
{
	
	$("div.comparision_list").pinFooter();
	fixArrows();
}

function fixArrows()
{
	var selectors = $('.comparision_list a.prev,.comparision_list a.next');
	if($('.listingMainWrapper').length < 5)
	{
		selectors.addClass("disabled");
	}else
	{
		selectors.removeClass("disabled");
	}
}

</script>
